﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using DomainModel.Entities;

namespace DAl
{
    public class NHibernateSample
    {
        private ISession _session;
        public ISession Session
        {
            set
            {
                _session = value;
            }
        }
        public NHibernateSample(ISession session)
        {
            _session = session;
        }

        public Customer GetCustomerById(int customerId)
        {
            return _session.Get<Customer>(customerId);
        }

        public IList<Customer> UseHQL_GetCustomersWithOrdersHavingProduct(DateTime orderDate)
        {
            return _session.CreateQuery("select c from Customer c ,"
                + " c.Orders.elements o where o.OrderDate >= :orderDate")
                .SetDateTime("orderDate", orderDate)
                .List<Customer>();
        }
    }
}
